<!--  -->
<template>
  <div>
    <div class="swipeBox">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="item in swipe" :key="item.id">
          <img :src="item.src">
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="goodInfo">
      <div class="title">{{goods.title}}</div>
      <div class="GoodsBox">
        <span class="mkrket">
          <strike>市场价: ¥ {{ goods.market_price }}</strike>
        </span>
        <span class="sP">
          销售价:
          <em>¥{{ goods.sell_price }}</em>
        </span>
      </div>
      <div class="countBox">
        <span>购买数量:</span>
        <van-stepper v-model="buyCount" min="1" :max="goods.stock_quantity"/>
      </div>
      <div class="btnBox">
        <van-button type="info">立即购买</van-button>
        <van-button type="danger" @click="addGoodsCart">加入购物车</van-button>
      </div>
    </div>
    <div class="paramsBox">
      <div class="title">商品参数</div>
      <div class="infoBox">
        <div>商品货号:{{goods.goods_no}}</div>
        <div>库存情况:{{goods.stock_quantity}}件</div>
        <div v-if="goods.add_time">上架时间:{{goods.add_time.slice(0,10)}}</div>
      </div>
      <div class="btnBox">
        <van-button plain type="info" @click="godesc">图文介绍</van-button>
        <van-button plain type="danger" @click="gocomments">商品评论</van-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      swipe: [],
      goods: [],
      buyCount: 1
    };
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.getGoodsDetail();
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {},
  methods: {
    async getGoodsDetail() {
      const { data: res } = await this.$http.get(
        `/api/goods/getinfo/${this.GoodsID}`
      );
      const { data: resImg } = await this.$http.get(
        `/api/getthumimages/${this.GoodsID}`
      );
      this.swipe = resImg.message;
      this.goods = res.message[0];
    },
    godesc() {
      this.$router.push("/goodsdesc/" + this.goods.id);
    },
    gocomments() {
      this.$router.push("/goodscomments/" + this.goods.id);
    },
    addGoodsCart() {}
  },
  computed: {
    GoodsID() {
      return this.$route.params.id;
    }
  }
};
</script>
<style lang="less" scoped>
.swipeBox,
.goodInfo,
.paramsBox {
  border: 1px solid #ccc;
  border-radius: 3px;
  overflow: hidden;
  box-sizing: border-box;
  text-align: center;
  margin: 10px;
}
.swipeBox {
  height: 230px;
  background-color: #fff;
  .my-swipe {
    height: 100%;
    .van-swipe-item {
      height: 100%;
      img {
        height: 100%;
      }
    }
  }
}
.goodInfo {
  height: 190px;
  padding: 10px;
  .GoodsBox {
    padding: 15px;
  }
  .mkrket {
    color: #8f8f94;
    font-size: 14px;
    margin: 0 10px;
  }
  .sP {
    color: #8f8f94;
    font-size: 14px;
    em {
      font-weight: 700;
      font-size: 16px;
      color: red;
      font-style: normal;
    }
  }
  .countBox {
    text-align: center;
    color: #8f8f94;
    font-size: 16px;
    margin-left: 25%;
    overflow: hidden;
    span {
      float: left;
      margin-right: 5px;
    }
    .van-stepper {
      float: left;
    }
  }
  .van-button {
    height: 35px;
    line-height: 35px;
    margin-top: 20px;
    margin-left: 10px;
    border: none;
  }
}
.paramsBox {
  height: 300px;
  padding: 10px;
  text-align: left;
  .infoBox {
    font-size: 14px;
    margin: 10px 0;
    color: #8f8f94;
    line-height: 30px;
    padding: 15px;
    border-bottom: 1px solid #ccc;
  }
  .van-button {
    width: 100%;
    margin-bottom: 5px;
  }
}

.title {
  border-bottom: 1px solid #ccc;
  padding-bottom: 10px;
  font-size: 15px;
}
</style>
